home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / gcc-2.95.3-3 / info / cpp.info-1 < prev    next >
Encoding:
GNU Info File  |  2001-07-15  |  48.9 KB  |  1,187 lines

  1. This is Info file cpp.info, produced by Makeinfo version 1.68 from the
  2. input file ./cpp.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * Cpp: (cpp).               The GNU C preprocessor.
  7. END-INFO-DIR-ENTRY
  8.  
  9.    This file documents the GNU C Preprocessor.
  10.  
  11.    Copyright 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1997, 1998 Free
  12. Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided also
  20. that the entire resulting derived work is distributed under the terms
  21. of a permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions.
  26.  
  27. 
  28. File: cpp.info,  Node: Top,  Next: Global Actions,  Up: (DIR)
  29.  
  30. The C Preprocessor
  31. ******************
  32.  
  33.    The C preprocessor is a "macro processor" that is used automatically
  34. by the C compiler to transform your program before actual compilation.
  35. It is called a macro processor because it allows you to define "macros",
  36. which are brief abbreviations for longer constructs.
  37.  
  38.    The C preprocessor provides four separate facilities that you can
  39. use as you see fit:
  40.  
  41.    * Inclusion of header files.  These are files of declarations that
  42.      can be substituted into your program.
  43.  
  44.    * Macro expansion.  You can define "macros", which are abbreviations
  45.      for arbitrary fragments of C code, and then the C preprocessor will
  46.      replace the macros with their definitions throughout the program.
  47.  
  48.    * Conditional compilation.  Using special preprocessing directives,
  49.      you can include or exclude parts of the program according to
  50.      various conditions.
  51.  
  52.    * Line control.  If you use a program to combine or rearrange source
  53.      files into an intermediate file which is then compiled, you can
  54.      use line control to inform the compiler of where each source line
  55.      originally came from.
  56.  
  57.    C preprocessors vary in some details.  This manual discusses the GNU
  58. C preprocessor, the C Compatible Compiler Preprocessor.  The GNU C
  59. preprocessor provides a superset of the features of ANSI Standard C.
  60.  
  61.    ANSI Standard C requires the rejection of many harmless constructs
  62. commonly used by today's C programs.  Such incompatibility would be
  63. inconvenient for users, so the GNU C preprocessor is configured to
  64. accept these constructs by default.  Strictly speaking, to get ANSI
  65. Standard C, you must use the options `-trigraphs', `-undef' and
  66. `-pedantic', but in practice the consequences of having strict ANSI
  67. Standard C make it undesirable to do this.  *Note Invocation::.
  68.  
  69.    The C preprocessor is designed for C-like languages; you may run into
  70. problems if you apply it to other kinds of languages, because it assumes
  71. that it is dealing with C.  For example, the C preprocessor sometimes
  72. outputs extra white space to avoid inadvertent C token concatenation,
  73. and this may cause problems with other languages.
  74.  
  75. * Menu:
  76.  
  77. * Global Actions::    Actions made uniformly on all input files.
  78. * Directives::        General syntax of preprocessing directives.
  79. * Header Files::      How and why to use header files.
  80. * Macros::            How and why to use macros.
  81. * Conditionals::      How and why to use conditionals.
  82. * Combining Sources:: Use of line control when you combine source files.
  83. * Other Directives::  Miscellaneous preprocessing directives.
  84. * Output::            Format of output from the C preprocessor.
  85. * Invocation::        How to invoke the preprocessor; command options.
  86. * Concept Index::     Index of concepts and terms.
  87. * Index::             Index of directives, predefined macros and options.
  88.  
  89. 
  90. File: cpp.info,  Node: Global Actions,  Next: Directives,  Prev: Top,  Up: Top
  91.  
  92. Transformations Made Globally
  93. =============================
  94.  
  95.    Most C preprocessor features are inactive unless you give specific
  96. directives to request their use.  (Preprocessing directives are lines
  97. starting with `#'; *note Directives::.).  But there are three
  98. transformations that the preprocessor always makes on all the input it
  99. receives, even in the absence of directives.
  100.  
  101.    * All C comments are replaced with single spaces.
  102.  
  103.    * Backslash-Newline sequences are deleted, no matter where.  This
  104.      feature allows you to break long lines for cosmetic purposes
  105.      without changing their meaning.
  106.  
  107.    * Predefined macro names are replaced with their expansions (*note
  108.      Predefined::.).
  109.  
  110.    The first two transformations are done *before* nearly all other
  111. parsing and before preprocessing directives are recognized.  Thus, for
  112. example, you can split a line cosmetically with Backslash-Newline
  113. anywhere (except when trigraphs are in use; see below).
  114.  
  115.      /*
  116.      */ # /*
  117.      */ defi\
  118.      ne FO\
  119.      O 10\
  120.      20
  121.  
  122. is equivalent into `#define FOO 1020'.  You can split even an escape
  123. sequence with Backslash-Newline.  For example, you can split `"foo\bar"'
  124. between the `\' and the `b' to get
  125.  
  126.      "foo\\
  127.      bar"
  128.  
  129. This behavior is unclean: in all other contexts, a Backslash can be
  130. inserted in a string constant as an ordinary character by writing a
  131. double Backslash, and this creates an exception.  But the ANSI C
  132. standard requires it.  (Strict ANSI C does not allow Newlines in string
  133. constants, so they do not consider this a problem.)
  134.  
  135.    But there are a few exceptions to all three transformations.
  136.  
  137.    * C comments and predefined macro names are not recognized inside a
  138.      `#include' directive in which the file name is delimited with `<'
  139.      and `>'.
  140.  
  141.    * C comments and predefined macro names are never recognized within a
  142.      character or string constant.  (Strictly speaking, this is the
  143.      rule, not an exception, but it is worth noting here anyway.)
  144.  
  145.    * Backslash-Newline may not safely be used within an ANSI "trigraph".
  146.      Trigraphs are converted before Backslash-Newline is deleted.  If
  147.      you write what looks like a trigraph with a Backslash-Newline
  148.      inside, the Backslash-Newline is deleted as usual, but it is then
  149.      too late to recognize the trigraph.
  150.  
  151.      This exception is relevant only if you use the `-trigraphs' option
  152.      to enable trigraph processing.  *Note Invocation::.
  153.  
  154. 
  155. File: cpp.info,  Node: Directives,  Next: Header Files,  Prev: Global Actions,  Up: Top
  156.  
  157. Preprocessing Directives
  158. ========================
  159.  
  160.    Most preprocessor features are active only if you use preprocessing
  161. directives to request their use.
  162.  
  163.    Preprocessing directives are lines in your program that start with
  164. `#'.  The `#' is followed by an identifier that is the "directive name".
  165. For example, `#define' is the directive that defines a macro.
  166. Whitespace is also allowed before and after the `#'.
  167.  
  168.    The set of valid directive names is fixed.  Programs cannot define
  169. new preprocessing directives.
  170.  
  171.    Some directive names require arguments; these make up the rest of
  172. the directive line and must be separated from the directive name by
  173. whitespace.  For example, `#define' must be followed by a macro name
  174. and the intended expansion of the macro.  *Note Simple Macros::.
  175.  
  176.    A preprocessing directive cannot be more than one line in normal
  177. circumstances.  It may be split cosmetically with Backslash-Newline,
  178. but that has no effect on its meaning.  Comments containing Newlines
  179. can also divide the directive into multiple lines, but the comments are
  180. changed to Spaces before the directive is interpreted.  The only way a
  181. significant Newline can occur in a preprocessing directive is within a
  182. string constant or character constant.  Note that most C compilers that
  183. might be applied to the output from the preprocessor do not accept
  184. string or character constants containing Newlines.
  185.  
  186.    The `#' and the directive name cannot come from a macro expansion.
  187. For example, if `foo' is defined as a macro expanding to `define', that
  188. does not make `#foo' a valid preprocessing directive.
  189.  
  190. 
  191. File: cpp.info,  Node: Header Files,  Next: Macros,  Prev: Directives,  Up: Top
  192.  
  193. Header Files
  194. ============
  195.  
  196.    A header file is a file containing C declarations and macro
  197. definitions (*note Macros::.) to be shared between several source
  198. files.  You request the use of a header file in your program with the C
  199. preprocessing directive `#include'.
  200.  
  201. * Menu:
  202.  
  203. * Header Uses::         What header files are used for.
  204. * Include Syntax::      How to write `#include' directives.
  205. * Include Operation::   What `#include' does.
  206. * Once-Only::        Preventing multiple inclusion of one header file.
  207. * Inheritance::         Including one header file in another header file.
  208.  
  209. 
  210. File: cpp.info,  Node: Header Uses,  Next: Include Syntax,  Prev: Header Files,  Up: Header Files
  211.  
  212. Uses of Header Files
  213. --------------------
  214.  
  215.    Header files serve two kinds of purposes.
  216.  
  217.    * System header files declare the interfaces to parts of the
  218.      operating system.  You include them in your program to supply the
  219.      definitions and declarations you need to invoke system calls and
  220.      libraries.
  221.  
  222.    * Your own header files contain declarations for interfaces between
  223.      the source files of your program.  Each time you have a group of
  224.      related declarations and macro definitions all or most of which
  225.      are needed in several different source files, it is a good idea to
  226.      create a header file for them.
  227.  
  228.    Including a header file produces the same results in C compilation as
  229. copying the header file into each source file that needs it.  But such
  230. copying would be time-consuming and error-prone.  With a header file,
  231. the related declarations appear in only one place.  If they need to be
  232. changed, they can be changed in one place, and programs that include
  233. the header file will automatically use the new version when next
  234. recompiled.  The header file eliminates the labor of finding and
  235. changing all the copies as well as the risk that a failure to find one
  236. copy will result in inconsistencies within a program.
  237.  
  238.    The usual convention is to give header files names that end with
  239. `.h'.  Avoid unusual characters in header file names, as they reduce
  240. portability.
  241.  
  242. 
  243. File: cpp.info,  Node: Include Syntax,  Next: Include Operation,  Prev: Header Uses,  Up: Header Files
  244.  
  245. The `#include' Directive
  246. ------------------------
  247.  
  248.    Both user and system header files are included using the
  249. preprocessing directive `#include'.  It has three variants:
  250.  
  251. `#include <FILE>'
  252.      This variant is used for system header files.  It searches for a
  253.      file named FILE in a list of directories specified by you, then in
  254.      a standard list of system directories.  You specify directories to
  255.      search for header files with the command option `-I' (*note
  256.      Invocation::.).  The option `-nostdinc' inhibits searching the
  257.      standard system directories; in this case only the directories you
  258.      specify are searched.
  259.  
  260.      The parsing of this form of `#include' is slightly special because
  261.      comments are not recognized within the `<...>'.  Thus, in
  262.      `#include <x/*y>' the `/*' does not start a comment and the
  263.      directive specifies inclusion of a system header file named
  264.      `x/*y'.  Of course, a header file with such a name is unlikely to
  265.      exist on Unix, where shell wildcard features would make it hard to
  266.      manipulate.
  267.  
  268.      The argument FILE may not contain a `>' character.  It may,
  269.      however, contain a `<' character.
  270.  
  271. `#include "FILE"'
  272.      This variant is used for header files of your own program.  It
  273.      searches for a file named FILE first in the current directory,
  274.      then in the same directories used for system header files.  The
  275.      current directory is the directory of the current input file.  It
  276.      is tried first because it is presumed to be the location of the
  277.      files that the current input file refers to.  (If the `-I-' option
  278.      is used, the special treatment of the current directory is
  279.      inhibited.)
  280.  
  281.      The argument FILE may not contain `"' characters.  If backslashes
  282.      occur within FILE, they are considered ordinary text characters,
  283.      not escape characters.  None of the character escape sequences
  284.      appropriate to string constants in C are processed.  Thus,
  285.      `#include "x\n\\y"' specifies a filename containing three
  286.      backslashes.  It is not clear why this behavior is ever useful, but
  287.      the ANSI standard specifies it.
  288.  
  289. `#include ANYTHING ELSE'
  290.      This variant is called a "computed #include".  Any `#include'
  291.      directive whose argument does not fit the above two forms is a
  292.      computed include.  The text ANYTHING ELSE is checked for macro
  293.      calls, which are expanded (*note Macros::.).  When this is done,
  294.      the result must fit one of the above two variants--in particular,
  295.      the expanded text must in the end be surrounded by either quotes
  296.      or angle braces.
  297.  
  298.      This feature allows you to define a macro which controls the file
  299.      name to be used at a later point in the program.  One application
  300.      of this is to allow a site-specific configuration file for your
  301.      program to specify the names of the system include files to be
  302.      used.  This can help in porting the program to various operating
  303.      systems in which the necessary system header files are found in
  304.      different places.
  305.  
  306. 
  307. File: cpp.info,  Node: Include Operation,  Next: Once-Only,  Prev: Include Syntax,  Up: Header Files
  308.  
  309. How `#include' Works
  310. --------------------
  311.  
  312.    The `#include' directive works by directing the C preprocessor to
  313. scan the specified file as input before continuing with the rest of the
  314. current file.  The output from the preprocessor contains the output
  315. already generated, followed by the output resulting from the included
  316. file, followed by the output that comes from the text after the
  317. `#include' directive.  For example, given a header file `header.h' as
  318. follows,
  319.  
  320.      char *test ();
  321.  
  322. and a main program called `program.c' that uses the header file, like
  323. this,
  324.  
  325.      int x;
  326.      #include "header.h"
  327.      
  328.      main ()
  329.      {
  330.        printf (test ());
  331.      }
  332.  
  333. the output generated by the C preprocessor for `program.c' as input
  334. would be
  335.  
  336.      int x;
  337.      char *test ();
  338.      
  339.      main ()
  340.      {
  341.        printf (test ());
  342.      }
  343.  
  344.    Included files are not limited to declarations and macro
  345. definitions; those are merely the typical uses.  Any fragment of a C
  346. program can be included from another file.  The include file could even
  347. contain the beginning of a statement that is concluded in the
  348. containing file, or the end of a statement that was started in the
  349. including file.  However, a comment or a string or character constant
  350. may not start in the included file and finish in the including file.
  351. An unterminated comment, string constant or character constant in an
  352. included file is considered to end (with an error message) at the end
  353. of the file.
  354.  
  355.    It is possible for a header file to begin or end a syntactic unit
  356. such as a function definition, but that would be very confusing, so
  357. don't do it.
  358.  
  359.    The line following the `#include' directive is always treated as a
  360. separate line by the C preprocessor even if the included file lacks a
  361. final newline.
  362.  
  363. 
  364. File: cpp.info,  Node: Once-Only,  Next: Inheritance,  Prev: Include Operation,  Up: Header Files
  365.  
  366. Once-Only Include Files
  367. -----------------------
  368.  
  369.    Very often, one header file includes another.  It can easily result
  370. that a certain header file is included more than once.  This may lead
  371. to errors, if the header file defines structure types or typedefs, and
  372. is certainly wasteful.  Therefore, we often wish to prevent multiple
  373. inclusion of a header file.
  374.  
  375.    The standard way to do this is to enclose the entire real contents
  376. of the file in a conditional, like this:
  377.  
  378.      #ifndef FILE_FOO_SEEN
  379.      #define FILE_FOO_SEEN
  380.      
  381.      THE ENTIRE FILE
  382.      
  383.      #endif /* FILE_FOO_SEEN */
  384.  
  385.    The macro `FILE_FOO_SEEN' indicates that the file has been included
  386. once already.  In a user header file, the macro name should not begin
  387. with `_'.  In a system header file, this name should begin with `__' to
  388. avoid conflicts with user programs.  In any kind of header file, the
  389. macro name should contain the name of the file and some additional
  390. text, to avoid conflicts with other header files.
  391.  
  392.    The GNU C preprocessor is programmed to notice when a header file
  393. uses this particular construct and handle it efficiently.  If a header
  394. file is contained entirely in a `#ifndef' conditional, then it records
  395. that fact.  If a subsequent `#include' specifies the same file, and the
  396. macro in the `#ifndef' is already defined, then the file is entirely
  397. skipped, without even reading it.
  398.  
  399.    There is also an explicit directive to tell the preprocessor that it
  400. need not include a file more than once.  This is called `#pragma once',
  401. and was used *in addition to* the `#ifndef' conditional around the
  402. contents of the header file.  `#pragma once' is now obsolete and should
  403. not be used at all.
  404.  
  405.    In the Objective C language, there is a variant of `#include' called
  406. `#import' which includes a file, but does so at most once.  If you use
  407. `#import' *instead of* `#include', then you don't need the conditionals
  408. inside the header file to prevent multiple execution of the contents.
  409.  
  410.    `#import' is obsolete because it is not a well designed feature.  It
  411. requires the users of a header file--the applications programmers--to
  412. know that a certain header file should only be included once.  It is
  413. much better for the header file's implementor to write the file so that
  414. users don't need to know this.  Using `#ifndef' accomplishes this goal.
  415.  
  416. 
  417. File: cpp.info,  Node: Inheritance,  Prev: Once-Only,  Up: Header Files
  418.  
  419. Inheritance and Header Files
  420. ----------------------------
  421.  
  422.    "Inheritance" is what happens when one object or file derives some
  423. of its contents by virtual copying from another object or file.  In the
  424. case of C header files, inheritance means that one header file includes
  425. another header file and then replaces or adds something.
  426.  
  427.    If the inheriting header file and the base header file have different
  428. names, then inheritance is straightforward: simply write `#include
  429. "BASE"' in the inheriting file.
  430.  
  431.    Sometimes it is necessary to give the inheriting file the same name
  432. as the base file.  This is less straightforward.
  433.  
  434.    For example, suppose an application program uses the system header
  435. `sys/signal.h', but the version of `/usr/include/sys/signal.h' on a
  436. particular system doesn't do what the application program expects.  It
  437. might be convenient to define a "local" version, perhaps under the name
  438. `/usr/local/include/sys/signal.h', to override or add to the one
  439. supplied by the system.
  440.  
  441.    You can do this by compiling with the option `-I.', and writing a
  442. file `sys/signal.h' that does what the application program expects.
  443. But making this file include the standard `sys/signal.h' is not so
  444. easy--writing `#include <sys/signal.h>' in that file doesn't work,
  445. because it includes your own version of the file, not the standard
  446. system version.  Used in that file itself, this leads to an infinite
  447. recursion and a fatal error in compilation.
  448.  
  449.    `#include </usr/include/sys/signal.h>' would find the proper file,
  450. but that is not clean, since it makes an assumption about where the
  451. system header file is found.  This is bad for maintenance, since it
  452. means that any change in where the system's header files are kept
  453. requires a change somewhere else.
  454.  
  455.    The clean way to solve this problem is to use `#include_next', which
  456. means, "Include the *next* file with this name."  This directive works
  457. like `#include' except in searching for the specified file: it starts
  458. searching the list of header file directories *after* the directory in
  459. which the current file was found.
  460.  
  461.    Suppose you specify `-I /usr/local/include', and the list of
  462. directories to search also includes `/usr/include'; and suppose both
  463. directories contain `sys/signal.h'.  Ordinary `#include <sys/signal.h>'
  464. finds the file under `/usr/local/include'.  If that file contains
  465. `#include_next <sys/signal.h>', it starts searching after that
  466. directory, and finds the file in `/usr/include'.
  467.  
  468. 
  469. File: cpp.info,  Node: Macros,  Next: Conditionals,  Prev: Header Files,  Up: Top
  470.  
  471. Macros
  472. ======
  473.  
  474.    A macro is a sort of abbreviation which you can define once and then
  475. use later.  There are many complicated features associated with macros
  476. in the C preprocessor.
  477.  
  478. * Menu:
  479.  
  480. * Simple Macros::    Macros that always expand the same way.
  481. * Argument Macros::  Macros that accept arguments that are substituted
  482.                        into the macro expansion.
  483. * Predefined::       Predefined macros that are always available.
  484. * Stringification::  Macro arguments converted into string constants.
  485. * Concatenation::    Building tokens from parts taken from macro arguments.
  486. * Undefining::       Cancelling a macro's definition.
  487. * Redefining::       Changing a macro's definition.
  488. * Macro Pitfalls::   Macros can confuse the unwary.  Here we explain
  489.                        several common problems and strange features.
  490.  
  491. 
  492. File: cpp.info,  Node: Simple Macros,  Next: Argument Macros,  Prev: Macros,  Up: Macros
  493.  
  494. Simple Macros
  495. -------------
  496.  
  497.    A "simple macro" is a kind of abbreviation.  It is a name which
  498. stands for a fragment of code.  Some people refer to these as "manifest
  499. constants".
  500.  
  501.    Before you can use a macro, you must "define" it explicitly with the
  502. `#define' directive.  `#define' is followed by the name of the macro
  503. and then the code it should be an abbreviation for.  For example,
  504.  
  505.      #define BUFFER_SIZE 1020
  506.  
  507. defines a macro named `BUFFER_SIZE' as an abbreviation for the text
  508. `1020'.  If somewhere after this `#define' directive there comes a C
  509. statement of the form
  510.  
  511.      foo = (char *) xmalloc (BUFFER_SIZE);
  512.  
  513. then the C preprocessor will recognize and "expand" the macro
  514. `BUFFER_SIZE', resulting in
  515.  
  516.      foo = (char *) xmalloc (1020);
  517.  
  518.    The use of all upper case for macro names is a standard convention.
  519. Programs are easier to read when it is possible to tell at a glance
  520. which names are macros.
  521.  
  522.    Normally, a macro definition must be a single line, like all C
  523. preprocessing directives.  (You can split a long macro definition
  524. cosmetically with Backslash-Newline.)  There is one exception: Newlines
  525. can be included in the macro definition if within a string or character
  526. constant.  This is because it is not possible for a macro definition to
  527. contain an unbalanced quote character; the definition automatically
  528. extends to include the matching quote character that ends the string or
  529. character constant.  Comments within a macro definition may contain
  530. Newlines, which make no difference since the comments are entirely
  531. replaced with Spaces regardless of their contents.
  532.  
  533.    Aside from the above, there is no restriction on what can go in a
  534. macro body.  Parentheses need not balance.  The body need not resemble
  535. valid C code.  (But if it does not, you may get error messages from the
  536. C compiler when you use the macro.)
  537.  
  538.    The C preprocessor scans your program sequentially, so macro
  539. definitions take effect at the place you write them.  Therefore, the
  540. following input to the C preprocessor
  541.  
  542.      foo = X;
  543.      #define X 4
  544.      bar = X;
  545.  
  546. produces as output
  547.  
  548.      foo = X;
  549.      
  550.      bar = 4;
  551.  
  552.    After the preprocessor expands a macro name, the macro's definition
  553. body is appended to the front of the remaining input, and the check for
  554. macro calls continues.  Therefore, the macro body can contain calls to
  555. other macros.  For example, after
  556.  
  557.      #define BUFSIZE 1020
  558.      #define TABLESIZE BUFSIZE
  559.  
  560. the name `TABLESIZE' when used in the program would go through two
  561. stages of expansion, resulting ultimately in `1020'.
  562.  
  563.    This is not at all the same as defining `TABLESIZE' to be `1020'.
  564. The `#define' for `TABLESIZE' uses exactly the body you specify--in
  565. this case, `BUFSIZE'--and does not check to see whether it too is the
  566. name of a macro.  It's only when you *use* `TABLESIZE' that the result
  567. of its expansion is checked for more macro names.  *Note Cascaded
  568. Macros::.
  569.  
  570. 
  571. File: cpp.info,  Node: Argument Macros,  Next: Predefined,  Prev: Simple Macros,  Up: Macros
  572.  
  573. Macros with Arguments
  574. ---------------------
  575.  
  576.    A simple macro always stands for exactly the same text, each time it
  577. is used.  Macros can be more flexible when they accept "arguments".
  578. Arguments are fragments of code that you supply each time the macro is
  579. used.  These fragments are included in the expansion of the macro
  580. according to the directions in the macro definition.  A macro that
  581. accepts arguments is called a "function-like macro" because the syntax
  582. for using it looks like a function call.
  583.  
  584.    To define a macro that uses arguments, you write a `#define'
  585. directive with a list of "argument names" in parentheses after the name
  586. of the macro.  The argument names may be any valid C identifiers,
  587. separated by commas and optionally whitespace.  The open-parenthesis
  588. must follow the macro name immediately, with no space in between.
  589.  
  590.    For example, here is a macro that computes the minimum of two numeric
  591. values, as it is defined in many C programs:
  592.  
  593.      #define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  594.  
  595. (This is not the best way to define a "minimum" macro in GNU C.  *Note
  596. Side Effects::, for more information.)
  597.  
  598.    To use a macro that expects arguments, you write the name of the
  599. macro followed by a list of "actual arguments" in parentheses,
  600. separated by commas.  The number of actual arguments you give must
  601. match the number of arguments the macro expects.   Examples of use of
  602. the macro `min' include `min (1, 2)' and `min (x + 28, *p)'.
  603.  
  604.    The expansion text of the macro depends on the arguments you use.
  605. Each of the argument names of the macro is replaced, throughout the
  606. macro definition, with the corresponding actual argument.  Using the
  607. same macro `min' defined above, `min (1, 2)' expands into
  608.  
  609.      ((1) < (2) ? (1) : (2))
  610.  
  611. where `1' has been substituted for `X' and `2' for `Y'.
  612.  
  613.    Likewise, `min (x + 28, *p)' expands into
  614.  
  615.      ((x + 28) < (*p) ? (x + 28) : (*p))
  616.  
  617.    Parentheses in the actual arguments must balance; a comma within
  618. parentheses does not end an argument.  However, there is no requirement
  619. for brackets or braces to balance, and they do not prevent a comma from
  620. separating arguments.  Thus,
  621.  
  622.      macro (array[x = y, x + 1])
  623.  
  624. passes two arguments to `macro': `array[x = y' and `x + 1]'.  If you
  625. want to supply `array[x = y, x + 1]' as an argument, you must write it
  626. as `array[(x = y, x + 1)]', which is equivalent C code.
  627.  
  628.    After the actual arguments are substituted into the macro body, the
  629. entire result is appended to the front of the remaining input, and the
  630. check for macro calls continues.  Therefore, the actual arguments can
  631. contain calls to other macros, either with or without arguments, or
  632. even to the same macro.  The macro body can also contain calls to other
  633. macros.  For example, `min (min (a, b), c)' expands into this text:
  634.  
  635.      ((((a) < (b) ? (a) : (b))) < (c)
  636.       ? (((a) < (b) ? (a) : (b)))
  637.       : (c))
  638.  
  639. (Line breaks shown here for clarity would not actually be generated.)
  640.  
  641.    If a macro `foo' takes one argument, and you want to supply an empty
  642. argument, you must write at least some whitespace between the
  643. parentheses, like this: `foo ( )'.  Just `foo ()' is providing no
  644. arguments, which is an error if `foo' expects an argument.  But `foo0
  645. ()' is the correct way to call a macro defined to take zero arguments,
  646. like this:
  647.  
  648.      #define foo0() ...
  649.  
  650.    If you use the macro name followed by something other than an
  651. open-parenthesis (after ignoring any spaces, tabs and comments that
  652. follow), it is not a call to the macro, and the preprocessor does not
  653. change what you have written.  Therefore, it is possible for the same
  654. name to be a variable or function in your program as well as a macro,
  655. and you can choose in each instance whether to refer to the macro (if
  656. an actual argument list follows) or the variable or function (if an
  657. argument list does not follow).
  658.  
  659.    Such dual use of one name could be confusing and should be avoided
  660. except when the two meanings are effectively synonymous: that is, when
  661. the name is both a macro and a function and the two have similar
  662. effects.  You can think of the name simply as a function; use of the
  663. name for purposes other than calling it (such as, to take the address)
  664. will refer to the function, while calls will expand the macro and
  665. generate better but equivalent code.  For example, you can use a
  666. function named `min' in the same source file that defines the macro.
  667. If you write `&min' with no argument list, you refer to the function.
  668. If you write `min (x, bb)', with an argument list, the macro is
  669. expanded.  If you write `(min) (a, bb)', where the name `min' is not
  670. followed by an open-parenthesis, the macro is not expanded, so you wind
  671. up with a call to the function `min'.
  672.  
  673.    You may not define the same name as both a simple macro and a macro
  674. with arguments.
  675.  
  676.    In the definition of a macro with arguments, the list of argument
  677. names must follow the macro name immediately with no space in between.
  678. If there is a space after the macro name, the macro is defined as
  679. taking no arguments, and all the rest of the line is taken to be the
  680. expansion.  The reason for this is that it is often useful to define a
  681. macro that takes no arguments and whose definition begins with an
  682. identifier in parentheses.  This rule about spaces makes it possible
  683. for you to do either this:
  684.  
  685.      #define FOO(x) - 1 / (x)
  686.  
  687. (which defines `FOO' to take an argument and expand into minus the
  688. reciprocal of that argument) or this:
  689.  
  690.      #define BAR (x) - 1 / (x)
  691.  
  692. (which defines `BAR' to take no argument and always expand into `(x) -
  693. 1 / (x)').
  694.  
  695.    Note that the *uses* of a macro with arguments can have spaces before
  696. the left parenthesis; it's the *definition* where it matters whether
  697. there is a space.
  698.  
  699. 
  700. File: cpp.info,  Node: Predefined,  Next: Stringification,  Prev: Argument Macros,  Up: Macros
  701.  
  702. Predefined Macros
  703. -----------------
  704.  
  705.    Several simple macros are predefined.  You can use them without
  706. giving definitions for them.  They fall into two classes: standard
  707. macros and system-specific macros.
  708.  
  709. * Menu:
  710.  
  711. * Standard Predefined::     Standard predefined macros.
  712. * Nonstandard Predefined::  Nonstandard predefined macros.
  713.  
  714. 
  715. File: cpp.info,  Node: Standard Predefined,  Next: Nonstandard Predefined,  Prev: Predefined,  Up: Predefined
  716.  
  717. Standard Predefined Macros
  718. ..........................
  719.  
  720.    The standard predefined macros are available with the same meanings
  721. regardless of the machine or operating system on which you are using
  722. GNU C.  Their names all start and end with double underscores.  Those
  723. preceding `__GNUC__' in this table are standardized by ANSI C; the rest
  724. are GNU C extensions.
  725.  
  726. `__FILE__'
  727.      This macro expands to the name of the current input file, in the
  728.      form of a C string constant.  The precise name returned is the one
  729.      that was specified in `#include' or as the input file name
  730.      argument.
  731.  
  732. `__LINE__'
  733.      This macro expands to the current input line number, in the form
  734.      of a decimal integer constant.  While we call it a predefined
  735.      macro, it's a pretty strange macro, since its "definition" changes
  736.      with each new line of source code.
  737.  
  738.      This and `__FILE__' are useful in generating an error message to
  739.      report an inconsistency detected by the program; the message can
  740.      state the source line at which the inconsistency was detected.
  741.      For example,
  742.  
  743.           fprintf (stderr, "Internal error: "
  744.                            "negative string length "
  745.                            "%d at %s, line %d.",
  746.                    length, __FILE__, __LINE__);
  747.  
  748.      A `#include' directive changes the expansions of `__FILE__' and
  749.      `__LINE__' to correspond to the included file.  At the end of that
  750.      file, when processing resumes on the input file that contained the
  751.      `#include' directive, the expansions of `__FILE__' and `__LINE__'
  752.      revert to the values they had before the `#include' (but
  753.      `__LINE__' is then incremented by one as processing moves to the
  754.      line after the `#include').
  755.  
  756.      The expansions of both `__FILE__' and `__LINE__' are altered if a
  757.      `#line' directive is used.  *Note Combining Sources::.
  758.  
  759. `__DATE__'
  760.      This macro expands to a string constant that describes the date on
  761.      which the preprocessor is being run.  The string constant contains
  762.      eleven characters and looks like `"Feb  1 1996"'.
  763.  
  764. `__TIME__'
  765.      This macro expands to a string constant that describes the time at
  766.      which the preprocessor is being run.  The string constant contains
  767.      eight characters and looks like `"23:59:01"'.
  768.  
  769. `__STDC__'
  770.      This macro expands to the constant 1, to signify that this is ANSI
  771.      Standard C.  (Whether that is actually true depends on what C
  772.      compiler will operate on the output from the preprocessor.)
  773.  
  774.      On some hosts, system include files use a different convention,
  775.      where `__STDC__' is normally 0, but is 1 if the user specifies
  776.      strict conformance to the C Standard.  The preprocessor follows
  777.      the host convention when processing system include files, but when
  778.      processing user files it follows the usual GNU C convention.
  779.  
  780.      This macro is not defined if the `-traditional' option is used.
  781.  
  782. `__STDC_VERSION__'
  783.      This macro expands to the C Standard's version number, a long
  784.      integer constant of the form `YYYYMML' where YYYY and MM are the
  785.      year and month of the Standard version.  This signifies which
  786.      version of the C Standard the preprocessor conforms to.  Like
  787.      `__STDC__', whether this version number is accurate for the entire
  788.      implementation depends on what C compiler will operate on the
  789.      output from the preprocessor.
  790.  
  791.      This macro is not defined if the `-traditional' option is used.
  792.  
  793. `__GNUC__'
  794.      This macro is defined if and only if this is GNU C.  This macro is
  795.      defined only when the entire GNU C compiler is in use; if you
  796.      invoke the preprocessor directly, `__GNUC__' is undefined.  The
  797.      value identifies the major version number of GNU CC (`1' for GNU CC
  798.      version 1, which is now obsolete, and `2' for version 2).
  799.  
  800. `__GNUC_MINOR__'
  801.      The macro contains the minor version number of the compiler.  This
  802.      can be used to work around differences between different releases
  803.      of the compiler (for example, if gcc 2.6.3 is known to support a
  804.      feature, you can test for `__GNUC__ > 2 || (__GNUC__ == 2 &&
  805.      __GNUC_MINOR__ >= 6)').  The last number, `3' in the example
  806.      above, denotes the bugfix level of the compiler; no macro contains
  807.      this value.
  808.  
  809. `__GNUG__'
  810.      The GNU C compiler defines this when the compilation language is
  811.      C++; use `__GNUG__' to distinguish between GNU C and GNU C++.
  812.  
  813. `__cplusplus'
  814.      The draft ANSI standard for C++ used to require predefining this
  815.      variable.  Though it is no longer required, GNU C++ continues to
  816.      define it, as do other popular C++ compilers.  You can use
  817.      `__cplusplus' to test whether a header is compiled by a C compiler
  818.      or a C++ compiler.
  819.  
  820. `__STRICT_ANSI__'
  821.      GNU C defines this macro if and only if the `-ansi' switch was
  822.      specified when GNU C was invoked.  Its definition is the null
  823.      string.  This macro exists primarily to direct certain GNU header
  824.      files not to define certain traditional Unix constructs which are
  825.      incompatible with ANSI C.
  826.  
  827. `__BASE_FILE__'
  828.      This macro expands to the name of the main input file, in the form
  829.      of a C string constant.  This is the source file that was specified
  830.      as an argument when the C compiler was invoked.
  831.  
  832. `__INCLUDE_LEVEL__'
  833.      This macro expands to a decimal integer constant that represents
  834.      the depth of nesting in include files.  The value of this macro is
  835.      incremented on every `#include' directive and decremented at every
  836.      end of file.  For input files specified by command line arguments,
  837.      the nesting level is zero.
  838.  
  839. `__VERSION__'
  840.      This macro expands to a string constant which describes the
  841.      version number of GNU C.  The string is normally a sequence of
  842.      decimal numbers separated by periods, such as `"2.6.0"'.
  843.  
  844. `__OPTIMIZE__'
  845.      GNU CC defines this macro in optimizing compilations.  It causes
  846.      certain GNU header files to define alternative macro definitions
  847.      for some system library functions.  You should not refer to or
  848.      test the definition of this macro unless you make very sure that
  849.      programs will execute with the same effect regardless.
  850.  
  851. `__CHAR_UNSIGNED__'
  852.      GNU C defines this macro if and only if the data type `char' is
  853.      unsigned on the target machine.  It exists to cause the standard
  854.      header file `limits.h' to work correctly.  You should not refer to
  855.      this macro yourself; instead, refer to the standard macros defined
  856.      in `limits.h'.  The preprocessor uses this macro to determine
  857.      whether or not to sign-extend large character constants written in
  858.      octal; see *Note The `#if' Directive: #if Directive..
  859.  
  860. `__REGISTER_PREFIX__'
  861.      This macro expands to a string (not a string constant) describing
  862.      the prefix applied to CPU registers in assembler code.  You can
  863.      use it to write assembler code that is usable in multiple
  864.      environments.  For example, in the `m68k-aout' environment it
  865.      expands to the null string, but in the `m68k-coff' environment it
  866.      expands to the string `%'.
  867.  
  868. `__USER_LABEL_PREFIX__'
  869.      Similar to `__REGISTER_PREFIX__', but describes the prefix applied
  870.      to user generated labels in assembler code.  For example, in the
  871.      `m68k-aout' environment it expands to the string `_', but in the
  872.      `m68k-coff' environment it expands to the null string.  This does
  873.      not work with the `-mno-underscores' option that the i386 OSF/rose
  874.      and m88k targets provide nor with the `-mcall*' options of the
  875.      rs6000 System V Release 4 target.
  876.  
  877. 
  878. File: cpp.info,  Node: Nonstandard Predefined,  Prev: Standard Predefined,  Up: Predefined
  879.  
  880. Nonstandard Predefined Macros
  881. .............................
  882.  
  883.    The C preprocessor normally has several predefined macros that vary
  884. between machines because their purpose is to indicate what type of
  885. system and machine is in use.  This manual, being for all systems and
  886. machines, cannot tell you exactly what their names are; instead, we
  887. offer a list of some typical ones.  You can use `cpp -dM' to see the
  888. values of predefined macros; see *Note Invocation::..
  889.  
  890.    Some nonstandard predefined macros describe the operating system in
  891. use, with more or less specificity.  For example,
  892.  
  893. `unix'
  894.      `unix' is normally predefined on all Unix systems.
  895.  
  896. `BSD'
  897.      `BSD' is predefined on recent versions of Berkeley Unix (perhaps
  898.      only in version 4.3).
  899.  
  900.    Other nonstandard predefined macros describe the kind of CPU, with
  901. more or less specificity.  For example,
  902.  
  903. `vax'
  904.      `vax' is predefined on Vax computers.
  905.  
  906. `mc68000'
  907.      `mc68000' is predefined on most computers whose CPU is a Motorola
  908.      68000, 68010 or 68020.
  909.  
  910. `m68k'
  911.      `m68k' is also predefined on most computers whose CPU is a 68000,
  912.      68010 or 68020; however, some makers use `mc68000' and some use
  913.      `m68k'.  Some predefine both names.  What happens in GNU C depends
  914.      on the system you are using it on.
  915.  
  916. `M68020'
  917.      `M68020' has been observed to be predefined on some systems that
  918.      use 68020 CPUs--in addition to `mc68000' and `m68k', which are
  919.      less specific.
  920.  
  921. `_AM29K'
  922. `_AM29000'
  923.      Both `_AM29K' and `_AM29000' are predefined for the AMD 29000 CPU
  924.      family.
  925.  
  926. `ns32000'
  927.      `ns32000' is predefined on computers which use the National
  928.      Semiconductor 32000 series CPU.
  929.  
  930.    Yet other nonstandard predefined macros describe the manufacturer of
  931. the system.  For example,
  932.  
  933. `sun'
  934.      `sun' is predefined on all models of Sun computers.
  935.  
  936. `pyr'
  937.      `pyr' is predefined on all models of Pyramid computers.
  938.  
  939. `sequent'
  940.      `sequent' is predefined on all models of Sequent computers.
  941.  
  942.    These predefined symbols are not only nonstandard, they are contrary
  943. to the ANSI standard because their names do not start with underscores.
  944. Therefore, the option `-ansi' inhibits the definition of these symbols.
  945.  
  946.    This tends to make `-ansi' useless, since many programs depend on the
  947. customary nonstandard predefined symbols.  Even system header files
  948. check them and will generate incorrect declarations if they do not find
  949. the names that are expected.  You might think that the header files
  950. supplied for the Uglix computer would not need to test what machine
  951. they are running on, because they can simply assume it is the Uglix;
  952. but often they do, and they do so using the customary names.  As a
  953. result, very few C programs will compile with `-ansi'.  We intend to
  954. avoid such problems on the GNU system.
  955.  
  956.    What, then, should you do in an ANSI C program to test the type of
  957. machine it will run on?
  958.  
  959.    GNU C offers a parallel series of symbols for this purpose, whose
  960. names are made from the customary ones by adding `__' at the beginning
  961. and end.  Thus, the symbol `__vax__' would be available on a Vax, and
  962. so on.
  963.  
  964.    The set of nonstandard predefined names in the GNU C preprocessor is
  965. controlled (when `cpp' is itself compiled) by the macro
  966. `CPP_PREDEFINES', which should be a string containing `-D' options,
  967. separated by spaces.  For example, on the Sun 3, we use the following
  968. definition:
  969.  
  970.      #define CPP_PREDEFINES "-Dmc68000 -Dsun -Dunix -Dm68k"
  971.  
  972. This macro is usually specified in `tm.h'.
  973.  
  974. 
  975. File: cpp.info,  Node: Stringification,  Next: Concatenation,  Prev: Predefined,  Up: Macros
  976.  
  977. Stringification
  978. ---------------
  979.  
  980.    "Stringification" means turning a code fragment into a string
  981. constant whose contents are the text for the code fragment.  For
  982. example, stringifying `foo (z)' results in `"foo (z)"'.
  983.  
  984.    In the C preprocessor, stringification is an option available when
  985. macro arguments are substituted into the macro definition.  In the body
  986. of the definition, when an argument name appears, the character `#'
  987. before the name specifies stringification of the corresponding actual
  988. argument when it is substituted at that point in the definition.  The
  989. same argument may be substituted in other places in the definition
  990. without stringification if the argument name appears in those places
  991. with no `#'.
  992.  
  993.    Here is an example of a macro definition that uses stringification:
  994.  
  995.      #define WARN_IF(EXP) \
  996.      do { if (EXP) \
  997.              fprintf (stderr, "Warning: " #EXP "\n"); } \
  998.      while (0)
  999.  
  1000. Here the actual argument for `EXP' is substituted once as given, into
  1001. the `if' statement, and once as stringified, into the argument to
  1002. `fprintf'.  The `do' and `while (0)' are a kludge to make it possible
  1003. to write `WARN_IF (ARG);', which the resemblance of `WARN_IF' to a
  1004. function would make C programmers want to do; see *Note Swallow
  1005. Semicolon::..
  1006.  
  1007.    The stringification feature is limited to transforming one macro
  1008. argument into one string constant: there is no way to combine the
  1009. argument with other text and then stringify it all together.  But the
  1010. example above shows how an equivalent result can be obtained in ANSI
  1011. Standard C using the feature that adjacent string constants are
  1012. concatenated as one string constant.  The preprocessor stringifies the
  1013. actual value of `EXP' into a separate string constant, resulting in
  1014. text like
  1015.  
  1016.      do { if (x == 0) \
  1017.              fprintf (stderr, "Warning: " "x == 0" "\n"); } \
  1018.      while (0)
  1019.  
  1020. but the C compiler then sees three consecutive string constants and
  1021. concatenates them into one, producing effectively
  1022.  
  1023.      do { if (x == 0) \
  1024.              fprintf (stderr, "Warning: x == 0\n"); } \
  1025.      while (0)
  1026.  
  1027.    Stringification in C involves more than putting doublequote
  1028. characters around the fragment; it is necessary to put backslashes in
  1029. front of all doublequote characters, and all backslashes in string and
  1030. character constants, in order to get a valid C string constant with the
  1031. proper contents.  Thus, stringifying `p = "foo\n";' results in `"p =
  1032. \"foo\\n\";"'.  However, backslashes that are not inside of string or
  1033. character constants are not duplicated: `\n' by itself stringifies to
  1034. `"\n"'.
  1035.  
  1036.    Whitespace (including comments) in the text being stringified is
  1037. handled according to precise rules.  All leading and trailing
  1038. whitespace is ignored.  Any sequence of whitespace in the middle of the
  1039. text is converted to a single space in the stringified result.
  1040.  
  1041. 
  1042. File: cpp.info,  Node: Concatenation,  Next: Undefining,  Prev: Stringification,  Up: Macros
  1043.  
  1044. Concatenation
  1045. -------------
  1046.  
  1047.    "Concatenation" means joining two strings into one.  In the context
  1048. of macro expansion, concatenation refers to joining two lexical units
  1049. into one longer one.  Specifically, an actual argument to the macro can
  1050. be concatenated with another actual argument or with fixed text to
  1051. produce a longer name.  The longer name might be the name of a function,
  1052. variable or type, or a C keyword; it might even be the name of another
  1053. macro, in which case it will be expanded.
  1054.  
  1055.    When you define a macro, you request concatenation with the special
  1056. operator `##' in the macro body.  When the macro is called, after
  1057. actual arguments are substituted, all `##' operators are deleted, and
  1058. so is any whitespace next to them (including whitespace that was part
  1059. of an actual argument).  The result is to concatenate the syntactic
  1060. tokens on either side of the `##'.
  1061.  
  1062.    Consider a C program that interprets named commands.  There probably
  1063. needs to be a table of commands, perhaps an array of structures
  1064. declared as follows:
  1065.  
  1066.      struct command
  1067.      {
  1068.        char *name;
  1069.        void (*function) ();
  1070.      };
  1071.      
  1072.      struct command commands[] =
  1073.      {
  1074.        { "quit", quit_command},
  1075.        { "help", help_command},
  1076.        ...
  1077.      };
  1078.  
  1079.    It would be cleaner not to have to give each command name twice,
  1080. once in the string constant and once in the function name.  A macro
  1081. which takes the name of a command as an argument can make this
  1082. unnecessary.  The string constant can be created with stringification,
  1083. and the function name by concatenating the argument with `_command'.
  1084. Here is how it is done:
  1085.  
  1086.      #define COMMAND(NAME)  { #NAME, NAME ## _command }
  1087.      
  1088.      struct command commands[] =
  1089.      {
  1090.        COMMAND (quit),
  1091.        COMMAND (help),
  1092.        ...
  1093.      };
  1094.  
  1095.    The usual case of concatenation is concatenating two names (or a
  1096. name and a number) into a longer name.  But this isn't the only valid
  1097. case.  It is also possible to concatenate two numbers (or a number and
  1098. a name, such as `1.5' and `e3') into a number.  Also, multi-character
  1099. operators such as `+=' can be formed by concatenation.  In some cases
  1100. it is even possible to piece together a string constant.  However, two
  1101. pieces of text that don't together form a valid lexical unit cannot be
  1102. concatenated.  For example, concatenation with `x' on one side and `+'
  1103. on the other is not meaningful because those two characters can't fit
  1104. together in any lexical unit of C.  The ANSI standard says that such
  1105. attempts at concatenation are undefined, but in the GNU C preprocessor
  1106. it is well defined: it puts the `x' and `+' side by side with no
  1107. particular special results.
  1108.  
  1109.    Keep in mind that the C preprocessor converts comments to whitespace
  1110. before macros are even considered.  Therefore, you cannot create a
  1111. comment by concatenating `/' and `*': the `/*' sequence that starts a
  1112. comment is not a lexical unit, but rather the beginning of a "long"
  1113. space character.  Also, you can freely use comments next to a `##' in a
  1114. macro definition, or in actual arguments that will be concatenated,
  1115. because the comments will be converted to spaces at first sight, and
  1116. concatenation will later discard the spaces.
  1117.  
  1118. 
  1119. File: cpp.info,  Node: Undefining,  Next: Redefining,  Prev: Concatenation,  Up: Macros
  1120.  
  1121. Undefining Macros
  1122. -----------------
  1123.  
  1124.    To "undefine" a macro means to cancel its definition.  This is done
  1125. with the `#undef' directive.  `#undef' is followed by the macro name to
  1126. be undefined.
  1127.  
  1128.    Like definition, undefinition occurs at a specific point in the
  1129. source file, and it applies starting from that point.  The name ceases
  1130. to be a macro name, and from that point on it is treated by the
  1131. preprocessor as if it had never been a macro name.
  1132.  
  1133.    For example,
  1134.  
  1135.      #define FOO 4
  1136.      x = FOO;
  1137.      #undef FOO
  1138.      x = FOO;
  1139.  
  1140. expands into
  1141.  
  1142.      x = 4;
  1143.      
  1144.      x = FOO;
  1145.  
  1146. In this example, `FOO' had better be a variable or function as well as
  1147. (temporarily) a macro, in order for the result of the expansion to be
  1148. valid C code.
  1149.  
  1150.    The same form of `#undef' directive will cancel definitions with
  1151. arguments or definitions that don't expect arguments.  The `#undef'
  1152. directive has no effect when used on a name not currently defined as a
  1153. macro.
  1154.  
  1155. 
  1156. File: cpp.info,  Node: Redefining,  Next: Macro Pitfalls,  Prev: Undefining,  Up: Macros
  1157.  
  1158. Redefining Macros
  1159. -----------------
  1160.  
  1161.    "Redefining" a macro means defining (with `#define') a name that is
  1162. already defined as a macro.
  1163.  
  1164.    A redefinition is trivial if the new definition is transparently
  1165. identical to the old one.  You probably wouldn't deliberately write a
  1166. trivial redefinition, but they can happen automatically when a header
  1167. file is included more than once (*note Header Files::.), so they are
  1168. accepted silently and without effect.
  1169.  
  1170.    Nontrivial redefinition is considered likely to be an error, so it
  1171. provokes a warning message from the preprocessor.  However, sometimes it
  1172. is useful to change the definition of a macro in mid-compilation.  You
  1173. can inhibit the warning by undefining the macro with `#undef' before the
  1174. second definition.
  1175.  
  1176.    In order for a redefinition to be trivial, the new definition must
  1177. exactly match the one already in effect, with two possible exceptions:
  1178.  
  1179.    * Whitespace may be added or deleted at the beginning or the end.
  1180.  
  1181.    * Whitespace may be changed in the middle (but not inside strings).
  1182.      However, it may not be eliminated entirely, and it may not be added
  1183.      where there was no whitespace at all.
  1184.  
  1185.    Recall that a comment counts as whitespace.
  1186.  
  1187.